package cn.tedu._03vehicle.base.interceptors;

import cn.tedu._03vehicle.pojo.vo.UserVo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

@Slf4j
@Configuration
public class LoginCheckInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.debug("进入登录校验状态");
        HttpSession session= request.getSession();
        UserVo userVo= (UserVo) session.getAttribute("user");
        if (userVo ==null){
            response.sendRedirect("/login.html");
        }

        return true;
    }
}
